package com.itheima.MQListener;

import com.alibaba.fastjson.JSON;
import com.itheima.pojo.Item;
import com.itheima.service.SearchService;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**     消息消费者
 * @Description SpringMQTest
 * @Author xiaoyang
 * @Date 2024-03-19
 */
@Component
public class MQRabbitListener {
        @Autowired
      private SearchService searchService;
    /**
     *
     * @param item
     * @throws InterruptedException
     */
//    @RabbitListener(queues = "item.queue")//queues:消息队列名
    @RabbitListener(queuesToDeclare = @Queue(name = "item.queue"))
    public void listenSimpleQueueMessage(String item) throws Exception {
        System.out.println("接收到了商品上架下架的消息");
        Item item1 = JSON.parseObject(item, Item.class);
        searchService.addDeleteItem(item1);
    }



}


